package tree.leetcode_144_medium;

import java.util.ArrayList;
import java.util.List;

public class PreorderTraversal {
    public List<Integer> preorderTraversal(TreeNode root){
        List<Integer> list = new ArrayList<>();
        dfs(list,root);
        return list;
    }
    public void dfs(List<Integer> list,TreeNode root){
        if(root == null){
            return;
        }
        list.add(root.val);
        dfs(list,root.left);
        dfs(list,root.right);
    }
}
